<!--# layout("/common/layout.html",{"jsBase":"/js/ncode/ncodebatch/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="batchId" id="batchId">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">批次名称</label>
				<div class="layui-input-inline">
                                <input type="text" name="batchName" id="batchName" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">权益名称</label>
				<div class="layui-input-inline">
                                <layui:simpleDataSelect name="roleId" id="roleId" value="${has(ncodebatch)?ncodebatch.roleId:''}" data="${roleList}"
                                            attrId="roleId" attrName="roleName" laySearch="true" />
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">省份</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="provinceId" id="provinceId" value="${has(ncodebatch)?ncodebatch.provinceId:''}" data="${provinceList}"
                                            attrId="provId" attrName="provName" laySearch="true"  layFilter="colFilter"/>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">N码类型</label>
				<div class="layui-input-inline">
                    <select style="width:40%"  name="nType" id="nType" selectValue="${ncodebatch.nType}">
                        <option value="2">体验卡</option>
                        <option value="4">正式会员卡</option>
                    </select>
				</div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">N码数量</label>
                <div class="layui-input-inline">
                    <input type="text" name="nCodeNum" id="nCodeNum" autocomplete="off" maxlength="50"
                           class="layui-input" lay-verify="required|number">
                </div>
            </div>

        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">有效截止期</label>
				<div class="layui-input-inline">
                    <input type="text" name="expiredDate"  id="expiredDate" autocomplete="off" class="layui-input input-date" >
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">有效天数</label>
				<div class="layui-input-inline">
                                <input type="text" name="validityDay" id="validityDay" autocomplete="off" maxlength="50" class="layui-input" >
				</div>
            </div>
        </div>
    </div>


    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">说明</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="remark"  id="remark" placeholder="请输入" class="layui-textarea" ></textarea>
                </div>
            </div>
        </div>
    </div>


    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','ncodebatchApi'], function(exports) {
    var form = layui.form;
    var ncodebatchApi = layui.ncodebatchApi;
    var index = layui.index;
    var laydate = layui.laydate;
    var isNew = true;
    <!--# if(!(isEmpty(ncodebatchJson))){  -->
    isNew = false;
    <!--# } -->

    //判断是否在前面加0
    function getNow(s) {
        return s < 10 ? '0' + s: s;
    }
    var myDate = new Date();
    var year=myDate.getFullYear();        //获取当前年
    var month=myDate.getMonth()+1;   //获取当前月
    var date=myDate.getDate();            //获取当前日

    var h=myDate.getHours();              //获取当前小时数(0-23)
    var m=myDate.getMinutes();          //获取当前分钟数(0-59)
    var s=myDate.getSeconds();
    var now=year+'-'+getNow(month)+"-"+getNow(date)+" "+getNow(h)+':'+getNow(m)+":"+getNow(s);
    laydate.render({
        elem: '#expiredDate'
        ,type: 'datetime'
        ,min: now
    });
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();

                let nType = $("#nType").val();
                let expiredDate = $("#expiredDate").val();
                let validityDay = $("#validityDay").val();
                if(nType==2&&expiredDate==""&&validityDay==""){
                    Common.info("请填写有效天数或有效期");
                    return;
                }
                var roleId = $("#roleId").val();
                if(roleId==""||roleId==null){
                    Common.info("请选择权益");
                    return ;
                }

                var provinceId = $("#provinceId").val();
                if(provinceId==""||provinceId==null){
                    Common.info("请选择省份");
                    return ;
                }

                form.on('submit(form)', function(){
                    ncodebatchApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(ncodebatchJson))){  -->
    var formJson = ${ncodebatchJson};
    console.dir(formJson);
    $("#nCodeNum").val(formJson.ncodeNum);
    $("#nType ").val(formJson.ntype);
    form.val("editform",formJson);
    <!--# } -->
});
</script>
